﻿using GraphicsTester.Scenarios;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Graphics.Platform;
using Microsoft.Maui.Graphics.Win2D;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;

namespace GraphicsTester.WinUI.Desktop
{
	/// <summary>
	/// An empty window that can be used on its own or navigated to within a Frame.
	/// </summary>
	public sealed partial class MainWindow : Window
	{
		public MainWindow()
		{
			this.InitializeComponent();
			Initialize();
		}

		public void Initialize()
		{
			GraphicsView.Background = new SolidColorBrush(global::Microsoft.UI.Colors.White);

			foreach (var scenario in ScenarioList.Scenarios)
			{
				List.Items.Add(scenario);
			}
			List.SelectionChanged += (source, args) => Drawable = List.SelectedItem as IDrawable;

			List.SelectedIndex = 0;

			this.SizeChanged += (source, args) => Draw();
		}

		public IDrawable Drawable
		{
			set
			{
				GraphicsView.Drawable = value;
				Draw();
			}
		}

		private void Draw()
		{
			GraphicsView.Invalidate();
		}
	}
}
